/**
 * 等待放款控制器
 */
import $_fn from '~plugins'
import '../index.less'
export default ['$scope','$rootScope','$location','$ui','http','$state',function($scope,$rootScope,$location,$ui,http,$state) {
  $scope.$_fn = $_fn
  $scope.err = {}
  $scope.search = !$_fn.isEmptyObject($location.search())?$location.search():{state:1}
  $scope.params = $scope.search
	//四级按钮
	$scope.tabMenu = $_fn.getCurrMenu($location.path())
  console.log($scope.tabMenu)
  $scope.subMenu = $scope.tabMenu.children[0].children
  console.log($scope.subMenu)
	console.log('等待放款控制器')
  $scope.errorToast = function(text) {
    $ui.toast({text:text,type:'warning',position:'center',appendTo:'.wp-container'});
  }
	//四级按钮页面跳转方法
	$scope.operation = function (path,id,item) {
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(item)
            $state.go(_path[1],item)
        }
        if(_path[0] == 'alert'){
        	console.log(id)
            $ui.modal({content:"<"+_path[1]+" id='"+id+"' itemData='"+params+"'></"+_path[1]+">"})
        }
    }
    //分页参数
    $scope.page = {
        current: $scope.search.pageNum ||  1
    }
	//初始化对象
	$scope.loan_type=0
	$scope.type=0
  $scope.params.s_id=2
  $scope.params.sIds=4

	//获取数据的函数
    $scope.getDada = function(page,params){
        params.pageNum = page
        http.post('selectOrderList.do',params,function (data) {
            var _data = data.data
            $scope.page.pageNum =  $scope.page.current
            $scope.page.pageSize = _data.pageSize
            $scope.page.total = _data.total
            if(data.errcode > 0){
                //列表无数据
                if(data.data.list.length === 0){
                    $scope.isData = true
                }
                $scope.$apply(function () {
                    $scope.dataList = data.data.list
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
        })
    }
	$scope.getDada('1', $scope.params)

	//搜索
  $scope.searchHandle = function () {
    if($scope.params.keyword && $scope.params.type==-1){
      $scope.err.type = true
      $scope.errorToast('左侧字段没有选择')
      return
    }
    $location.search($scope.params)
    $scope.getDada(1,$scope.params)
  }
  $scope.name1 = '还款方式'
  $scope.name2 = '贷款方式'
  $scope.name3 = '申请期限'
  $scope.select = [{name:'以租代购',value:1},{name:'信贷方式',value:2}]
  $scope.popup = {
      opened: true
  }
  $scope.open = function () {
      $scope.popup.opened = !$scope.popup.opened
  }
}]
